package com.example.mybatis.mapper;

import com.example.mybatis.model.UserInfo;
import org.apache.ibatis.annotations.*;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.List;

@Mapper
public interface UserInfoMapper extends BaseMapper<UserInfo>{
    @Select("select *from user_info")
    List<UserInfo>SelectAll();


    @Select("SELECT id,username,`password`,age,gender,phone,delete_flag AS deleteFlag," +
            "create_time AS createTime,update_time AS updateTime from user_info;")
    List<UserInfo>SelectAll1();

    @Results(id = "resultMap",value = {
            @Result(column = "delete_flag",property = "deleteFlag"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime")
    })
    @Select("select *from user_info")
    List<UserInfo>SelectAll2();


    @Select("select *from user_info")
    List<UserInfo>SelectAll3();

    @ResultMap("resultMap")
    @Select("select *from user_info where id<#{id}")
    List<UserInfo>Select(Integer x);

    @Select("select *from user_info where username=#{arg1} and password=#{arg0}")
    List<UserInfo>SelectByNameAndPassword(String username,String password);

    @Options(useGeneratedKeys=true,keyProperty = "id")
    @Insert("INSERT INTO user_info ( username, `password`, age, gender, phone )VALUES (#{userInfo.username},#{userInfo.password},#{userInfo.age},#{userInfo.gender},#{userInfo.phone} )")
Integer Insert(@Param("userInfo") UserInfo userInfo);

    @Delete("DELETE FROM user_info WHERE id=#{id}")
Integer Delete(Integer id);

    @Update("UPDATE user_info SET username='白龙马' WHERE id=#{id}")
Integer Update(Integer id);

}
